package com.twu.biblioteca;

import com.twu.biblioteca.core.Book;
import com.twu.biblioteca.core.Menu;
import com.twu.biblioteca.core.Movie;
import com.twu.biblioteca.core.User;
import com.twu.biblioteca.option.*;
import com.twu.biblioteca.service.BookService;
import com.twu.biblioteca.service.MovieService;
import com.twu.biblioteca.service.UserService;
import com.twu.biblioteca.util.Cli;

class BibliotecaAppFactory {
    public static BibliotecaApp createBibliotecaApp() {
        BibliotecaApp app = new BibliotecaApp();
        app.setWelcomeMessage("Welcome to Biblioteca");
        app.setCli(new Cli());
        app.setMenu(configMenu(app));
        return app;
    }

    public static Menu configMenu(BibliotecaApp app) {
        Menu result = new Menu(app.getCli());

        BookService bookService = initBookService();
        MovieService movieService = initMovieService();
        UserService userService = initUserService();

        result.addOption(new ListBookOption(bookService, app.getCli()));
        result.addOption(new ReserveBookOption(bookService, app.getCli()));
        result.addOption(new MemberDetailsOption(app.getCli(), app));
        result.addOption(new MovieOption(movieService, app.getCli()));
        result.addOption(new LoginOption(userService, app.getCli(), app));

        return result;
    }

    private static UserService initUserService() {
        UserService userService = new UserService();
        userService.addUser(new User("111-1111", "123456"));
        userService.addUser(new User("111-1112", "123456"));
        userService.addUser(new User("111-1113", "123456"));
        return userService;
    }

    private static MovieService initMovieService() {
        MovieService movieService = new MovieService();
        movieService.addMovie(new Movie("Movie A", 1990, "Director A", "1"));
        movieService.addMovie(new Movie("Movie B", 2000, "Director B", "2"));
        movieService.addMovie(new Movie("Movie C", 2010, "Director C"));
        return movieService;
    }

    private static BookService initBookService() {
        BookService bookService = new BookService();
        bookService.addBook(new Book("A"));
        bookService.addBook(new Book("B"));
        bookService.addBook(new Book("C"));
        return bookService;
    }
}
